package edu.student.models;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.util.DB;

public class Syllabus {

	
	private String chapterName;
	
	//Returns the syllabus(chapter nos. and chapter names) for a specific subject code.
	public static ArrayList<Syllabus> findSyllabus(String subjectCode){
		
		ArrayList<Syllabus> selection = new ArrayList<Syllabus>();
		Connection con = DB.getConnection();
		String query = "SELECT  SYLLABUS.CHAPTER_NAME "
				+ "FROM SYLLABUS, SUBJECT "
				+ "WHERE SYLLABUS.SUBJECT_ID = SUBJECT.SUBJECT_ID AND "
				+ "SUBJECT.SUBJECT_CODE = '" + subjectCode + "' ";
		ResultSet result = DB.readFromDB(query, con);
		
		try {
			while (result.next()) {
				Syllabus s1 = new Syllabus();
				//s1.chapterNo = result.getInt("SYLLABUS.CHAPTER_NO");
				s1.chapterName = result.getString("SYLLABUS.CHAPTER_NAME");
				selection.add(s1);		
			}
		} catch (SQLException e) {
	       System.out.println("Exception while reading from db"+ e);
		}
		DB.close(con);
		
		return selection;
	}
	
	
	public String getChapterName() {
		return chapterName;
	}
	public void setChapterName(String chapterName) {
		this.chapterName = chapterName;
	}
	
	
}
